package com.fourpigeon.dao;

import com.fourpigeon.domain.BlogDeal;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 交易贴
 * 数据库操作
 */
@Mapper
@Repository
public interface BlogDealDao {
    @Select("select * from tb_blog_deal where userId = #{userId} and id < #{startId} and status < 2 order by createTime DESC limit 6")
    public List<BlogDeal> getByUserId(Long userId,Long startId);
    @Select("select * from tb_blog_deal where id = #{id} and status < 2")
    public BlogDeal getById(Long id);
    @Select("select * from tb_blog_deal where status < 2")
    public List<BlogDeal> getAll();
    @Update("update tb_blog_deal set type=#{type},userName=#{userName},name=#{name},price=#{price},contact=#{contact},content=#{content},status=#{status},images=#{images} where id = #{id}")
    public boolean update(BlogDeal blogDeal);
    @Insert("insert into tb_blog_deal values(#{id},#{userId},#{userName},#{icon},#{type},#{name},#{price},#{contact},#{content},#{images},#{status},#{createTime},#{updateTime})")
    public boolean save(BlogDeal blogDeal);
    @Delete("delete from tb_blog_deal where id = #{id}")
    public boolean delete(Long id);
//    @Select("select * from tb_blog_deal where id < #{start} order by createTime DESC,id DESC limit 3")
//    public List<BlogDeal> getDailys(Integer start);
    @Select("select * from tb_blog_deal where id < #{start} and status < 2 order by createTime DESC,id DESC limit 6")
    public List<BlogDeal> getDailys(Long start);

    @Select("select * from tb_blog_deal where (name like concat('%', #{searchKeyWord}, '%') or content like concat('%', #{searchKeyWord}, '%')) and status < 2 and type = #{type}")
    public List<BlogDeal> getSearchDeals(String searchKeyWord, Short type);

    @Select("select * from tb_blog_deal where name like concat('%', #{searchKeyWord}, '%') or content like concat('%', #{searchKeyWord}, '%') and status < 2")
    public List<BlogDeal> getAllSearchDeals(String searchKeyWord);

    @Select("select * from tb_blog_deal where type = #{type} and status < 2 limit 6")
    public List<BlogDeal> getByType(Short type);

    @Select("select * from tb_blog_deal where status < 2 order by createTime DESC")
    public List<BlogDeal> getHotDeal();

    @Update("update tb_blog_deal set status = 1 where id = #{id}")
    public boolean reportBlog(Long id);
}
